package org.diffshop.coupon.service.impl;

import org.diffshop.common.to.SpuBoundTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.diffshop.common.utils.PageUtils;
import org.diffshop.common.utils.Query;

import org.diffshop.coupon.dao.SmsSpuBoundsDao;
import org.diffshop.coupon.entity.SmsSpuBoundsEntity;
import org.diffshop.coupon.service.SmsSpuBoundsService;


@Service("smsSpuBoundsService")
public class SmsSpuBoundsServiceImpl extends ServiceImpl<SmsSpuBoundsDao, SmsSpuBoundsEntity> implements SmsSpuBoundsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SmsSpuBoundsEntity> page = this.page(
                new Query<SmsSpuBoundsEntity>().getPage(params),
                new QueryWrapper<SmsSpuBoundsEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 保存spuBound
     * @param spuBoundTO
     */
    @Override
    public void save(SpuBoundTO spuBoundTO) {
        if (!spuBoundTO.getBuyBounds().equals(0L) || !spuBoundTO.getGrowBounds().equals(0L)){
            SmsSpuBoundsEntity spuBoundsEntity = new SmsSpuBoundsEntity();
            spuBoundsEntity.setSpuId(spuBoundTO.getSpuId());
            BeanUtils.copyProperties(spuBoundTO, spuBoundsEntity);
            baseMapper.insert(spuBoundsEntity);
        }
    }

}
